<template>
  <div class="app-container calendar-list-container">
    <el-table :key='tableKey' :data="list" v-loading="listLoading" element-loading-text="给我一点时间"  fit highlight-current-row
      style="width: 100%">
      <el-table-column
      type="selection"
      width="55">
    </el-table-column>
      <el-table-column align="center" label="AppId" width="100">
        <template slot-scope="scope">
          <span>{{scope.row.AppId}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="TemplateId" width="100">
        <template slot-scope="scope">
          <span>{{scope.row.TemplateId}}</span>
        </template>
      </el-table-column>
      <el-table-column min-width="150px" label="模板名称">
        <template slot-scope="scope">
          <span >{{scope.row.Name}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="150" fixed="right">
        <template slot-scope="scope">
          <el-button type="text"   size="mini" @click="handledialogForm(scope.row.AppId,scope.row.TemplateId,scope.row.Name)">更新</el-button>
        </template>
      </el-table-column>
    </el-table>
     <!-- Form -->
      <el-dialog :title="'请输入需要更新的编号' + '(' + form.name + ')'" :visible.sync="dialogFormVisible">
        <el-form :model="form">
          <el-form-item label="AppId" :label-width="formLabelWidth">
            <el-input v-model="form.AppId" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item label="TemplateId" :label-width="formLabelWidth">
            <el-input v-model="form.TemplateId" auto-complete="off"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="handleUpdate()">确 定</el-button>
        </div>
     </el-dialog>
  </div>
</template>

<script>
import { productList, updateTemplateid } from "@/api/product";
import waves from "@/directive/waves"; // 水波纹指令
import { parseTime } from "@/utils";

export default {
  name: "productlist",
  directives: {
    waves
  },
  data() {
    return {
      tableKey: 0,
      list: [],
      total: null,
      listLoading: true,
      listQuery: {
        pageNumber: 1,
        itemsPerPage: 35
      },
      dialogFormVisible: false,
      form: {
          AppId: 0,
          TemplateId:0,
          name:"",
          type: []
        },
      formLabelWidth: '80px'
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      //列表数据
      this.listLoading = true;
      productList(this.listQuery).then(response => {
        if (response.data.Code === 0) {
          this.list = response.data.Data.Items;
          this.total = response.data.Data.TotalItems;
        } else {
          this.$message({
            type: "danger",
            message: response.data.Message
          });
        }
        this.listLoading = false;
      });
    },

   //弹出框
    handledialogForm(appid,templateid,name){
      this.dialogFormVisible = true;
      this.form.AppId = appid;
      this.form.TemplateId = templateid; 
      this.form.name = name;
    },
    
    //更新小程序模板
    handleUpdate() {
      let appid = this.form.AppId;
      let templateid = this.form.TemplateId;
      this.dialogFormVisible = false;
      console.log(templateid)
      updateTemplateid({appId:appid,templateId:templateid}).then(response => {
        if (response.data.Code === 0) {
          this.$message({
              type: "success",
              message:"更新成功"
          });
          this.getList();
        } else {
          this.$message({
            type: "danger",
            message: response.data.Message
          });
        }
      });
    }
  }
};
</script>


